package com.dd.admin.business.stockDetail.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.dd.admin.common.model.UpdateGroup;
import com.dd.admin.common.model.result.ResultBean;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
import com.dd.admin.business.stockDetail.entity.StockDetail;
import com.dd.admin.business.stockDetail.domain.StockDetailVo;
import com.dd.admin.business.stockDetail.domain.StockDetailDto;
import com.dd.admin.business.stockDetail.service.StockDetailService;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 727869402@qq.com
 * @since 2024-06-27
 */
@Api(tags = "")
@RestController
public class StockDetailController {

    @Autowired
    StockDetailService stockDetailService;

    @ApiOperation(value = "-分页列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("/admin/stockDetail/page")
    public ResultBean<IPage<StockDetailVo>> page(StockDetailDto stockDetailDto) {
        IPage<StockDetailVo> pageInfo = stockDetailService.selectStockDetailPage(stockDetailDto);
        return ResultBean.success(pageInfo);
    }

    @ApiOperation(value = "-列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("/admin/stockDetail/list")
    public ResultBean<List<StockDetailVo>> list(StockDetailDto stockDetailDto) {
        List<StockDetailVo> list = stockDetailService.selectStockDetailList(stockDetailDto);
        return ResultBean.success(list);
    }

    @ApiOperation(value = "-添加")
    @ApiOperationSupport(order = 3)
    @PostMapping("/admin/stockDetail/add")
    public ResultBean<StockDetail> add(@RequestBody @Validated StockDetailDto stockDetailDto) {
        StockDetail stockDetail = BeanUtil.copyProperties(stockDetailDto, StockDetail.class);
        stockDetailService.save(stockDetail);
        return ResultBean.success(stockDetail);
    }

    @ApiOperation(value = "-查询")
    @ApiOperationSupport(order = 4)
    @GetMapping("/admin/stockDetail/{stockDetailId}")
    public ResultBean<StockDetailVo> get(@PathVariable @NotBlank String stockDetailId) {
        StockDetail stockDetail = stockDetailService.getById(stockDetailId);
        StockDetailVo stockDetailVo = BeanUtil.copyProperties(stockDetail,StockDetailVo.class);
        return ResultBean.success(stockDetailVo);
    }

    @ApiOperation(value = "-修改")
    @ApiOperationSupport(order = 5)
    @PostMapping("/admin/stockDetail/update")
    public ResultBean<StockDetail> update(@RequestBody @Validated(UpdateGroup.class) StockDetailDto stockDetailDto) {
        StockDetail stockDetail = BeanUtil.copyProperties(stockDetailDto, StockDetail.class);
        stockDetailService.updateById(stockDetail);
        return ResultBean.success(stockDetail);
    }

    @ApiOperation(value = "-删除")
    @ApiOperationSupport(order = 6)
    @GetMapping("/admin/stockDetail/delete/{stockDetailId}")
    public ResultBean<StockDetail> delete(@PathVariable @NotBlank String stockDetailId) {
        Boolean b = stockDetailService.removeById(stockDetailId);
        return ResultBean.success(b);
    }
}
